package com.wcll.www;
import java.util.*;
import java.sql.*;
public class JianLiBean {
	private int id;
	private String genid;
	private String gcname;
	private String gcprovince;
	private String gcareacity;
	private String gcareacounty;
	private String gcsex;
	private String gcemail;
	private String gcphone;
	private String gccontact;
	private String cishu;
	private String diqu;
	private final int PAGE_ROWS = 20;
	private static Connection con = null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getGenid() {
		return genid;
	}
	public void setGenid(String genid) {
		this.genid = genid;
	}
	public String getGcname() {
		return gcname;
	}
	public void setGcname(String gcname) {
		this.gcname = gcname;
	}
	public String getGcprovince() {
		return gcprovince;
	}
	public void setGcprovince(String gcprovince) {
		this.gcprovince = gcprovince;
	}
	public String getGcareacity() {
		return gcareacity;
	}
	public void setGcareacity(String gcareacity) {
		this.gcareacity = gcareacity;
	}
	public String getGcareacounty() {
		return gcareacounty;
	}
	public void setGcareacounty(String gcareacounty) {
		this.gcareacounty = gcareacounty;
	}
	public String getGcsex() {
		return gcsex;
	}
	public void setGcsex(String gcsex) {
		this.gcsex = gcsex;
	}
	public String getGcemail() {
		return gcemail;
	}
	public void setGcemail(String gcemail) {
		this.gcemail = gcemail;
	}
	public String getGcphone() {
		return gcphone;
	}
	public void setGcphone(String gcphone) {
		this.gcphone = gcphone;
	}
	public String getGccontact() {
		return gccontact;
	}
	public void setGccontact(String gccontact) {
		this.gccontact = gccontact;
	}
	public String getCishu() {
		return cishu;
	}
	public void setCishu(String cishu) {
		this.cishu = cishu;
	}
	public String getDiqu() {
		return diqu;
	}
	public void setDiqu(String diqu) {
		this.diqu = diqu;
	}
	public static Connection getCon() throws ClassNotFoundException, SQLException {
		if(con==null){
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost/jobs?useUnicode=true&characterEncoding=UTF8","root","");
		}
		return con;
	}
	public static void setCon(Connection con) {
		JianLiBean.con = con;
	}
	public ArrayList<JianLiBean> getJianLi(){
		ArrayList<JianLiBean> al = new ArrayList<JianLiBean>();
		try{
			con = JianLiBean.getCon();
			Statement st = con.createStatement();
			Statement st1 = con.createStatement();
			ResultSet rs = st.executeQuery("select * from genericusersinfo order by id desc");
			while(rs.next()){
				JianLiBean jlb = new JianLiBean();
				jlb.setId(rs.getInt("id"));
				jlb.setGenid(rs.getString("gen_id"));
				jlb.setGcname(rs.getString("gc_name"));
				jlb.setGcprovince(rs.getString("gc_province"));
				jlb.setGcareacity(rs.getString("gc_areacity"));
				jlb.setGcareacounty(rs.getString("gc_areacounty"));
				ResultSet rs1 = st1.executeQuery("select name from area where id='"+jlb.getGcprovince()+"' or id='"+jlb.getGcareacity()+"' or id='"+jlb.getGcareacounty()+"'");
				String s = "";
				while(rs1.next()){
					s +=rs1.getString("name");
				}
				jlb.setDiqu(s);
				jlb.setGcsex(rs.getString("gc_sex"));
				jlb.setGcemail(rs.getString("gc_email"));
				jlb.setGcphone(rs.getString("gc_phone"));
				jlb.setGccontact(rs.getString("gc_contact"));
				jlb.setCishu(rs.getString("cishu"));
				al.add(jlb);
				rs1.close();
				}
			rs.close();
			st.close();
			}catch(Exception e){}
		return al;
	}
	public int getCounts(){
		int pages = 0;
		double totals;
		
		try{
			con = GenBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select count(*) as a from genericusersinfo");
			while(rs.next()){
				totals = (double)rs.getInt("a");
				pages = (int)Math.ceil(totals/this.PAGE_ROWS);
			}
		}catch(Exception e){}
		return pages;
	}
}
